/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/*数量累加*/
function add(obj) {
    var key =obj.value;
    var goodsid = $("#goods_id").val();
    $.ajax({
            type:"post",
            url:"http://www.quanvisa.com/ajax_goods.php",
            data:"goodsid="+goodsid+"&key="+key,
            dataType:"json",
            success:function(result){
                        $("#show_select_prive_1").text(result.price);
                        $("#show_select_prive_2").text(result.price1);
                        $("#show_select_prive_3").text(result.price2);
                        $("#show_num_1").text(result.discount1);
                        $("#show_num_2").text(Number(result.discount1)+1);
                        $("#show_num_3").text(result.discount2);
                        $("#show_num_4").text(result.discount2);
                        // $("#show_explain_place").text(result.place);
                        // $("#show_explain_face").text(result.face);
                        // $("#show_explain_time").text(result.time);
                        // $("#show_explain_times").text(result.time);
                        // $("#show_explain_how").text(result.how);
                        // $("#show_explain_stop").text(result.stop);
                        // $("#show_explain_range").text(result.range);
                        // $("#show_explain_num").text(result.num);
                        // $("#show_explain_percent").text(result.percent);
                        find();
                       }
                });
        function find(){
            var num = $("#show_select_num_"+key).val();
            if (num <= 0) {
                         num = 0;
             }
             if (num >= 999) {
                 num = 998;
             }
             var goodsnum1= $("#show_num_1").text();
             var goodsnum3 = $("#show_num_3").text();
             var price1 = $("#show_select_prive_1").text();
             var price2 = $("#show_select_prive_2").text();
             var price3 = $("#show_select_prive_3").text();
             $("#show_select_num_"+key).val(Number(num) + 1);
             var newnum = Number(num) + 1;
             if( newnum <= goodsnum1){
                 var number = newnum*price1;
             }else if( newnum > goodsnum1 && newnum <= goodsnum3 ){
                 var number = newnum*price2;
             }else if( newnum > goodsnum3){
                  var number = newnum*price3;
             }
             $("#show_select_sum_"+key).text(number.toFixed(2));
             sumadd();
        };
};
/*数量累减*/
function des(obj) {
    var key =obj.value;
    var num = $("#show_select_num_"+key).val();
    var goodsid = $("#goods_id").val();
    $.ajax({
           type:"post",
            url:"http://www.quanvisa.com/ajax_goods.php",
            data:"goodsid="+goodsid+"&key="+key,
            dataType:"json",
            success:function(result){
                        $("#show_select_prive_1").text(result.price);
                        $("#show_select_prive_2").text(result.price1);
                        $("#show_select_prive_3").text(result.price2);
                        $("#show_num_1").text(result.discount1);
                        $("#show_num_2").text(Number(result.discount1)+1);
                        $("#show_num_3").text(result.discount2);
                        $("#show_num_4").text(result.discount2);
                        // $("#show_explain_place").text(result.place);
                        // $("#show_explain_face").text(result.face);
                        // $("#show_explain_time").text(result.time);
                        // $("#show_explain_times").text(result.time);
                        // $("#show_explain_how").text(result.how);
                        // $("#show_explain_stop").text(result.stop);
                        // $("#show_explain_range").text(result.range);
                        // $("#show_explain_num").text(result.num);
                        // $("#show_explain_percent").text(result.percent);    
                        find();
                       }
                });
   function find(){
    var num = $("#show_select_num_"+key).val();
    if (num <= 0) {
		num = 1;
    }
    if (num >= 999) {
	num = 999;
    }
    var goodsnum1= $("#show_num_1").text();
    var goodsnum3 = $("#show_num_3").text();
    var price1 = $("#show_select_prive_1").text();
    var price2 = $("#show_select_prive_2").text();
    var price3 = $("#show_select_prive_3").text();
    $("#show_select_num_"+key).val(Number(num) - 1);
    var newnum = Number(num) -1;
    if( newnum <= goodsnum1){
        var number = newnum*price1;
    }else if( newnum > goodsnum1 && newnum <= goodsnum3 ){
        var number = newnum*price2;
    }else if( newnum > goodsnum3){
         var number = newnum*price3;
    }
    $("#show_select_sum_"+key).text(number.toFixed(2));
    sumadd();
   };
};
function alerts(){
            alert("请选择产品类型后操作！");
 };
 /*提示消息遮罩层*/
$(function (){	
    if($(".show_main_select_change_num").find("input").attr("disabled")=="disabled"){
        $(".show_main_select_content_num").append(' <div class="show_main_select_change_num_float" onclick="alerts();" ></div');
    };
/*输入框获取焦点*/
$(".show_select_num").focus(function(){
    $(this).val("");
    var key = $(this).attr("key");
    var goodsid = $("#goods_id").val();
    $.ajax({
            type:"post",
            url:"http://www.quanvisa.com/ajax_goods.php",
            data:"goodsid="+goodsid+"&key="+key,
            dataType:"json",
            success:function(result){
                        $("#show_select_prive_1").text(result.price);
                        $("#show_select_prive_2").text(result.price1);
                        $("#show_select_prive_3").text(result.price2);
                        $("#show_num_1").text(result.discount1);
                        $("#show_num_2").text(Number(result.discount1)+1);
                        $("#show_num_3").text(result.discount2);
                        $("#show_num_4").text(result.discount2);
                        // $("#show_explain_place").text(result.place);
                        // $("#show_explain_face").text(result.face);
                        // $("#show_explain_time").text(result.time);
                        // $("#show_explain_times").text(result.time);
                        // $("#show_explain_how").text(result.how);
                        // $("#show_explain_stop").text(result.stop);
                        // $("#show_explain_range").text(result.range);
                        // $("#show_explain_num").text(result.num);
                        // $("#show_explain_percent").text(result.percent);     
                      }
               });
});
/*输入框的值变化*/
 $(".show_select_num").keyup(function() {
    var thisid = $(this).attr("id");
    var sumid = $(this).attr("sum");
    var nums = Number($("#"+thisid).val());
    var goodsnum1= Number($("#show_num_1").text());
    var goodsnum3 = Number($("#show_num_3").text());
    var price1 = $("#show_select_prive_1").text();
    var price2 = $("#show_select_prive_2").text();
    var price3 = $("#show_select_prive_3").text();
    var test= /^[0-9]*$/;
    if(!test.test(nums)){
        alert("请输入正确数字!");
        $("#"+thisid).val("0");
        $(sumid).text("00.00" );
        return;
    }
    if( nums < 1){
        alert("请输入1-999之间的数量!");
        $("#"+thisid).val("0");
        $(sumid).text("00.00" );
        var sumber = 0;
        $(sumid).text(sumber.toFixed(2));
        sumadd();
        return;
    }else if(nums  > 999) {
        alert("请输入1-999之间的数量!");
	$("#"+thisid).val("999");
        var sumber=999*price3;
        $(sumid).text(sumber.toFixed(2));
        sumadd();
   }else{
        if( nums <= goodsnum1){
            var sumber = nums*price1;
        };
        if( nums > goodsnum1 && nums <= goodsnum3 ){
            var sumber = nums*price2;
        };
        if( nums > goodsnum3){
             var sumber = nums*price3;
        }
        $(sumid).text(sumber.toFixed(2) );
        sumadd();
   }
   });
/*输入框失去焦点*/
$(".show_select_num").blur(function(){
    var thisid = $(this).attr("id");
    var sumid = $(this).attr("sum");
    var nums = Number($("#"+thisid).val());
    var test= /^[0-9]*$/;
    if(!test.test(nums)){
        $("#"+thisid).val("0");
        $(sumid).text("00.00" );
        return;
    }
    if ( nums < 1){
        $("#"+thisid).val("0");
        $(sumid).text("00.00" );
        sumadd();
        return;
    };
   });
/*产品类型选择*/
$(".show_main_select_content_text").click( function(){
       if( $(this).find(".show_main_selected").css("display")=="none" ){
           $(this).find(".show_main_selected").css({"display":"block"});
           $(this).next().find(".show_main_select_change_num_float").remove();
           $(this).next().find("button").removeAttr("disabled");
           $(this).next().find("input").removeAttr("disabled");
           var key= $(this).next().find("button").val();
           var goodsid = $("#goods_id").val();
           $.ajax({
                    type:"post",
                    url:"http://www.quanvisa.com/ajax_goods.php",
                    data:"goodsid="+goodsid+"&key="+key,
                    dataType:"json",
                    success:function(result){
                                 $("#show_select_prive_1").text(result.price);
                                 $("#show_select_prive_2").text(result.price1);
                                 $("#show_select_prive_3").text(result.price2);
                                 $("#show_num_1").text(result.discount1);
                                 $("#show_num_2").text(Number(result.discount1)+1);
                                 $("#show_num_3").text(result.discount2);
                                 $("#show_num_4").text(result.discount2);
                                 // $("#show_explain_place").text(result.place);
                                 // $("#show_explain_face").text(result.face);
                                 // $("#show_explain_time").text(result.time);
                                 // $("#show_explain_times").text(result.times);
                                 // $("#show_explain_how").text(result.how);
                                 // $("#show_explain_stop").text(result.stop);
                                 // $("#show_explain_range").text(result.range);
                                 // $("#show_explain_num").text(result.num);
                                 // $("#show_explain_percent").text(result.percent);     
		                }
		         });
       }else if( $(this).find(".show_main_selected").css("display")=="block" ){
           $(this).find(".show_main_selected").css({"display":"none"});
           $(this).next().find(".show_main_select_content_num").append('<div class="show_main_select_change_num_float" onclick="alerts();" ></div');
           $(this).next().find("button").attr({"disabled":"disabled"});
           $(this).next().find("input").attr({"disabled":"disabled"});
           $(this).next().find("input").val("0");
           $(this).next().find(".show_select_sum").text("00.00");
           sumadd();
       }
   });   
$("#show_data_title_ul li").click(function(){
    $(this).siblings().removeClass();
    $(this).siblings().addClass("show_data_title_ul_li");
    $(this).removeClass("show_data_title_ul_li");
    $(this).addClass("show_data_title_ul_li_mouse");
});
//表单提交
$("#form_back").submit(function(){
    var text= $(this).find("textarea").val();
    var name= $(this).find("input[name='name']").val();
    var phone=$(this).find("input[name='phone']").val();
    var reg=/^1[3|4|5|7|8]\d{3,9}$/;
    var flag = "";
    if(text=="请输入姓名联系方式或邮箱后提交问题"){
        $(this).find("textarea").removeClass();
        $(this).find("textarea").addClass("show_form_text_empty");
        $(this).find("textarea").attr({"disabled":"true"});
        setTimeout(function () { 
        $("#form_back").find("textarea").removeClass();
        $("#form_back").find("textarea").addClass("show_form_text_textarea");
        $("#form_back").find("textarea").removeAttr("disabled");
        }, 1500);
        flag = "1";
    }else if(text.length <=10){
        $(this).find("textarea").removeClass();
        $(this).find("textarea").val("请输入10个字以上");
        $(this).find("textarea").addClass("show_form_text_empty");
        $(this).find("textarea").attr({"disabled":"true"});
        setTimeout(function () { 
        $("#form_back").find("textarea").removeClass();
        $("#form_back").find("textarea").val("请输入姓名联系方式或邮箱后提交问题");
        $("#form_back").find("textarea").addClass("show_form_text_textarea");  
        $("#form_back").find("textarea").removeAttr("disabled");
        }, 1500);
        flag = "1";
    }
    if(name=="请输入姓名"){
         $(this).find("input[name='name']").css({"color":"#FF9D00","backgroundColor":"rgba(255,157,0,0.1)","borderColor":"#FF9D00"});
         $(this).find("input[name='name']").attr({"disabled":"true"});
         setTimeout(function () { 
        $("#form_back").find("input[name='name']").css({"color":"#C8C8C8","backgroundColor":"#FFF","borderColor":"#F1F1F1"});
        $("#form_back").find("input[name='name']").removeAttr("disabled");
        }, 1500);
        flag = "1";
    };
    if(phone=="请输入手机号"){
        $(this).find("input[name='phone']").css({"color":"#FF9D00","backgroundColor":"rgba(255,157,0,0.1)","borderColor":"#FF9D00"});
        $(this).find("input[name='phone']").attr({"disabled":"true"});
        setTimeout(function () { 
        $("#form_back").find("input[name='phone']").css({"color":"#C8C8C8","backgroundColor":"#FFF","borderColor":"#F1F1F1"});
        $("#form_back").find("input[name='phone']").removeAttr("disabled");
        }, 1500);
        flag = "1";
    }else if(!reg.test(name)){
        $(this).find("input[name='phone']").css({"color":"#FF9D00","backgroundColor":"rgba(255,157,0,0.1)","borderColor":"#FF9D00"});
        $(this).find("input[name='phone']").val("请输入正确的手机号");
        $(this).find("input[name='phone']").attr({"disabled":"true"});
        setTimeout(function () { 
        $("#form_back").find("input[name='phone']").css({"color":"#C8C8C8","backgroundColor":"#FFF","borderColor":"#F1F1F1"});
        $("#form_back").find("input[name='phone']").val("请输入手机号");
        $("#form_back").find("input[name='phone']").removeAttr("disabled"); 
        }, 1500);
        flag = "1";
    };
    if(flag!=""){
       return false;
    }
});
 $("#form_back").find("textarea").blur(function(){
    var text=$(this).val();
    if(text==""){
        $(this).removeClass();
        $(this).addClass("show_form_text_empty");
        $(this).val("请输入姓名联系方式或邮箱后提交问题");
        $(this).attr({"disabled":"true"});
        setTimeout(function () { 
        $("#form_back").find("textarea").removeClass();
        $("#form_back").find("textarea").addClass("show_form_text_textarea");
        $("#form_back").find("textarea").removeAttr("disabled");
        }, 1000);   
    }
 });
$("#form_back").find("input[name='name']").blur(function(){
    var name=$(this).val();
    if(name==""){
        $(this).css({"color":"#FF9D00","backgroundColor":"rgba(255,157,0,0.1)","borderColor":"#FF9D00"});
        $(this).val("请输入姓名");
        $(this).attr({"disabled":"true"});
        setTimeout(function () { 
            $("#form_back").find("input[name='name']").css({"color":"#C8C8C8","backgroundColor":"#FFF","borderColor":"#F1F1F1"});
           
            $("#form_back").find("input[name='name']").removeAttr("disabled");
        }, 1000);
   }
});
$("#form_back").find("input[name='phone']").blur(function(){
    var phone=$(this).val();
    var reg=/^1[34578]\d{9}$/;
    if(phone==""){
        $(this).css({"color":"#FF9D00","backgroundColor":"rgba(255,157,0,0.1)","borderColor":"#FF9D00"});
        $(this).val("请输入手机号");
        $(this).attr({"disabled":"true"});
        setTimeout(function () { 
            $("#form_back").find("input[name='phone']").css({"color":"#C8C8C8","backgroundColor":"#FFF","borderColor":"#F1F1F1"});
            $("#form_back").find("input[name='phone']").removeAttr("disabled");
        }, 1000);
    }else if(!reg.test(name)){
        $(this).css({"color":"#FF9D00","backgroundColor":"rgba(255,157,0,0.1)","borderColor":"#FF9D00"});
        $(this).val("请输入正确的手机号");
        $(this).attr({"disabled":"true"});
        setTimeout(function () { 
        $("#form_back").find("input[name='phone']").css({"color":"#C8C8C8","backgroundColor":"#FFF","borderColor":"#F1F1F1"});
        $("#form_back").find("input[name='phone']").removeAttr("disabled"); 
        }, 1000);
    };
});

//产品套餐超出隐藏
$("#show_hidden_more").click(function(){
    if($(this).html()=="显示更多"){
       $("#hidden_show").css({"display":"block"});
       $(this).html("收起");
    }else{
       $("#hidden_show").css({"display":"none"});
       $(this).html("显示更多"); 
    }
});
});
/*数量累加*/
function sumadd(){
    var sumnum =0;
    for(var i=0;i<=$(".show_select_sum").length-1;i++){
        sumnum += Number($("#show_select_sum_"+i).text());
    }
    $(".show_main_sum_sunnum").text(Number(sumnum).toFixed(2));
 };
 
$(window).scroll(function(){
    var typeheight=$("#show_type").outerHeight(true);
    var dataheight=$("#show_data").outerHeight(true);
    var knowheight=$("#show_know").outerHeight(true);
    var questionheight=$("#show_question").outerHeight(true);
    var navtop = $("#show_nav").offset().top;
    if($(document).scrollTop()>=navtop){
        $("#show_nav_display").css({"display":"inline-block"});
        if($(document).scrollTop()< (Number(navtop)+Number(typeheight))){
           var checka= $("[href='#show_type']").parent()
               checka.siblings().removeClass();
               checka.siblings().addClass("show_message_title_ul_li");
               checka.removeClass("show_message_title_ul_li");
               checka.addClass("show_message_title_ul_li_check");
        }else if($(document).scrollTop() <(Number(navtop)+Number(typeheight)+Number(dataheight))){
             var checka= $("[href='#show_data']").parent()
               checka.siblings().removeClass();
               checka.siblings().addClass("show_message_title_ul_li");
               checka.removeClass("show_message_title_ul_li");
               checka.addClass("show_message_title_ul_li_check");
        }else if($(document).scrollTop() <(Number(navtop)+Number(typeheight)+Number(dataheight)+Number(knowheight))){
             var checka= $("[href='#show_know']").parent()
               checka.siblings().removeClass();
               checka.siblings().addClass("show_message_title_ul_li");
               checka.removeClass("show_message_title_ul_li");
               checka.addClass("show_message_title_ul_li_check");
        }else {
            var checka= $("[href='#show_question']").parent()
               checka.siblings().removeClass();
               checka.siblings().addClass("show_message_title_ul_li");
               checka.removeClass("show_message_title_ul_li");
               checka.addClass("show_message_title_ul_li_check");
        }
    }else{
        $("#show_nav_display").css({"display":"none"});
        var checka=$(".show_message_title_ul_li");
               checka.siblings().removeClass();
               checka.siblings().addClass("show_message_title_ul_li");
    };
});

function fundata(a){
    for(i=1;i<=5;i++){
      var display=(a==i)?"block":"none";
          $("#show_data_"+i).css({"display":display});
    };
};
